package com.shared.job;

import com.shared.dao.PCouponMapper;
import com.shared.pojo.PCoupon;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;

@Component
public class PCouponJob {
    @Autowired
    private PCouponMapper pCouponMapper;

    //@Scheduled(cron = "0/10 * * * * ?")
    public void initCoupon() {
        List<PCoupon> list = pCouponMapper.findPcoupon();
        for (PCoupon pCoupon : list) {
            String date = pCoupon.getEndtime();
            SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss");
            String res = simpleDateFormat.format(new Date().getTime());
            if (date.equals(res)) {
                pCouponMapper.uodateCoupon(pCoupon.getId(), 1);
            }
        }
    }
}
